package com.coder520.sync_learning.demo.singleton;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class SaveAndRead {
	public static void main(String[] args) {
		try {
			MyObject myObject=MyObject.getInstance();
			
			FileOutputStream fos=new FileOutputStream("E:\\myObject.txt");
			
			ObjectOutputStream oos=new ObjectOutputStream(fos);
			
			oos.writeObject(myObject);
			
			oos.close();
			fos.close();
			
			System.out.println(myObject.hashCode());
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		try {
			FileInputStream fins=new FileInputStream("E:\\myObject.txt");
			
			ObjectInputStream ois=new ObjectInputStream(fins);
			
			MyObject myObject=(MyObject) ois.readObject();
			
			System.out.println(myObject.toString());
			ois.close();
			fins.close();
			System.out.println(myObject.hashCode());
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
